import { defineStore } from 'pinia'
import service from '../service/service'
export const useVideoStore = defineStore('video', {
	state() {
		return {
			videoInfo: {
				author: {},
				title: '',
				path: '',
				type: '',
				cover: '',
				auditStatus: 0,
				likeCount: 0
			},
			searchTitle: '',
			showVideo: []
		}
	},
	actions: {
		initVideo() {
			this.showVideo = []
		},
		getAllVideo() {
			service({
				method: 'post',
				url: '/wuli-video/page',
				data: {
					data: {
						direction: 'DESC',
						pageNum: 0,
						pageSize: 100,
						property: 'updateDateTime',
					},
					params: {
						title: this.searchTitle
					},
				},
			}).then((result: any) => {
				if (result.data.code === 200) {
					const formattedVideos = result.data.data.content.map((video: any) => {
						const formattedDate = new Date(video.createDateTime)
							.toISOString()
							.split('T')[0]
						return {
							...video,
							createDateTime: formattedDate,
						}
					})
					console.log(formattedVideos)
					this.showVideo = formattedVideos
				}
			})
		}
	},
	persist: {
		enabled: true
	}
})